package com.miracle.blog.controller;


import com.miracle.blog.dto.CategoryBackDTO;
import com.miracle.blog.dto.CategoryOptionDTO;
import com.miracle.blog.service.CategoryService;
import com.miracle.blog.vo.ConditionVO;
import com.miracle.blog.vo.PageResult;
import com.miracle.blog.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 分类模块
 *
 * */
@RestController
public class CategoryController {

    @Autowired
    private CategoryService categoryService;
    /**
     * 搜索文章分类
     *
     * */
    @GetMapping("/admin/categories/search")
    public Result<List<CategoryOptionDTO>> listCategoriesBySearch(ConditionVO conditionVO){
        System.out.println(conditionVO);
        return Result.ok(categoryService.listCategoriesBySearch(conditionVO));
    }

    /**
     * 查看后台分类列表
     *
     * @param condition 条件
     * @return {@link Result<CategoryBackDTO>} 后台分类列表
     */
    @ApiOperation(value = "查看后台分类列表")
    @GetMapping("/admin/categories")
    public Result<PageResult<CategoryBackDTO>> listBackCategories(ConditionVO condition) {
        return Result.ok(categoryService.listBackCategories(condition));
    }
}
